/**
 * Created by Administrator on 2016/7/2.
 */

//验证码倒计时
var countdown=120;
function settime(obj) {
    if (countdown == 0) {
        obj.removeAttribute("disabled");
        obj.innerHTML="获取验证码";
        return;
    } else {
        obj.setAttribute("disabled", true);
        obj.innerHTML="重新发送(" + countdown + ")";
        countdown--;
    }
    setTimeout(function() {
            settime(obj) }
        ,1000)
}
var session_id = sessionStorage.session_id;
//Ajax验证码接口请求
$("document").ready(function(){
    $("#securityCode").click(function(){
        var value = $(".ceilPhone").val();
        var user_token =  sessionStorage.user_token;
        $.post(commonval+"/sendTelMsValCode",{
            type:"api_register",
            tel:value,
            user_token:user_token,
            device:"wap",
            session_id:session_id
        },function(data){
            var status = data.status;
            if(status == 0){
                createWindow(data.msg);
            }else if(status == 1){
                createWindow("发送成功");
                $("body>section>input:first-child").css("display","none");
                $("#confirm1").css("display","none");
                $("#confirm2").css("display","block");
                $("section>section:nth-child(2)").css("display","block");
            }
            function createWindow(msg) {
                var window =$("<section class='showMsg'></section>");
                var show = "<p>"+msg+"</p>";
                window.append(show);
                $("body").append(window);
                setTimeout("$('.showMsg').remove()",3000);
            }
        })
    })
})

/*
//修改手机号
$("document").ready(function(){
    $("#confirm1").click(function(){
        var token = $.md5("http://dev.haotoufa.com/updatePassWord@haotoufa");
        var u_id = sessionStorage.u_id;
        var tel = $(".ceilPhone").val();
        var code = $(".securityCode").val();
        $.post("http://dev.haotoufa.com/updatePassWord",{
            u_id:u_id,
            token:token,
            tel:tel,
            code:code,
        },function(data){
            if (data.status == 1) {
                createWindow("修改手机号成功");
                location.href ='changeInfo.html';
                sessionStorage["username"] = tel;
            } else if (data.status == 0) {
                createWindow(data.msg);
            }
            function createWindow(msg) {
                var window =$("<section class='showMsg'></section>");
                var show = "<p>"+msg+"</p>";
                window.append(show);
                $("body").append(window);
                setTimeout("$('.showMsg').remove()",3000);
            }

        });
    });
});
*/

//第一步发送验证码
$("document").ready(function(){
    $("#confirm1").click(function(){
        $("#securityCode").click();
    });
});
//第二步注册手机号
//修改手机号
$("document").ready(function(){
    $("#confirm2").click(function(){
        var user_token =  sessionStorage.user_token;
        var u_id = sessionStorage.u_id;
        var tel = $(".ceilPhone").val();
        var code = $(".securityCode").val();
        $.post(commonval+"/updatePassWord",{
            u_id:u_id,
            user_token:user_token,
            device:"wap",
            tel:tel,
            code:code,
            session_id:session_id
        },function(data){
            if (data.status == 1) {
                createWindow("修改手机号成功");
                location.href ='changeInfo.html';
                sessionStorage["username"] = tel;
            } else if (data.status == 0) {
                createWindow(data.msg);
            }
            function createWindow(msg) {
                var window =$("<section class='showMsg'></section>");
                var show = "<p>"+msg+"</p>";
                window.append(show);
                $("body").append(window);
                setTimeout("$('.showMsg').remove()",3000);
            }

        });
    });
});